import * as type from '../mutation-types'
import Storage from '../../utils/storage'

// initial state
// shape: [{ id, quantity }]

const state = {
    routerList:[],
    routerAnimation:'router',
    documentClick:true,
    deviceId:Storage.get(`anniu_deviceId`) || '',
    deviceName:Storage.get(`anniu_deviceName`) || '',
    configInfo:'',
    clientId:Storage.get(`pingguodai_clientId`) || '',
    authIdImgs:Storage.get(`pingguodai_authIdImgs`) || {},
    bizRole:Storage.get(`youjie_${Storage.get('channel')}_bizRole`),
    geoLocation:Storage.get(`anniu_location`) || {},
    share:{
        show:false,
        info:{}
    },
    scrollOut:'',
    scrollIn:'',
    unreadNum:0,
    lendList:[],
    lendPageInfo:Storage.get(`youjie_${Storage.get('channel')}_lendPageInfo`) || {},
    borrowList:[],
    borrowPageInfo:Storage.get(`youjie_${Storage.get('channel')}_borrowPageInfo`) || {},
    reportId:'',
    goHome:true,
    lendFilterStr:'',
    borrowFilterStr:'',
    borrowFilterObj:{},
    userInfo:Storage.get(`51sjd_userInfo`) || {},
    needLogin:false,
    reportInfo:'',
    loanIndexRefresh:false,
    hasTradePassword:false,
    loginPassword:'',
    transactionPassword:'',
    funcIds:[],
    cityInfo : {},
    carInfo:{},
    channel:Storage.get('channel'),
    admin:Storage.get('admin'),
    sessionId:Storage.get(`pingguodai_sessionId`),
    selectZIndex:1,
    searchHistoryCurrentPage:1,
    searchHistory:{},
    searchHistoryForm:{
        startTime: '',
        endTime: '',
        searchType:{
            value:'',
            text:'所有服务'
        },
        searchCondition:{
            value:'身份证',
            text:'身份证'
        },
        idNumber:'',
    },
    policyHistory:[],
    invoiceSupport:[],
    invoiceResult:{},
    blackListResult:{},
    operatorsResult:{},
    creditCardBillResult:[],
    studentStatusResult:{},
    providentFundResult:{},
    providentFundCity:[],
    authType:'auto',
    userId:0,
    carCurrent:'请选择车型',
    updateDashboard:true,
    dashboard:{},
    requestParams:{},
    baodanResult:JSON.parse(localStorage.getItem('daze-baodan-result') || '[]'),
    companyList:[],
    shows:{
        showpg:true,
        showpg11:false,
    },
}

// mutations
const mutations = {
    [type.SET_DEVICEID]( state , str ) {
        state.deviceId = str
    },
    [type.SET_CONFIGINFO]( state , object ) {
        state.configInfo = object
    },
    [type.SET_GEOLOCATION]( state , obj ) {
        state.geoLocation = obj
    },
    [type.SET_AUTHIDIMGS]( state , obj ) {
        if(obj == 'remove'){
            state.authIdImgs = {}
            return
        }
        console.log(obj)
        let key = obj.pos
        let value = obj.url
        state.authIdImgs[key] = value
    },
    [type.SET_DEVICENAME]( state , str ) {
        state.deviceName = str
    },
    [type.SET_CLIENTID]( state , str ) {
        state.clientId = str
    },
    [type.SET_SCROLLIN]( state , str ) {
        state.scrollIn = str
    },
    [type.SET_SCROLLOUT]( state , str ) {
        state.scrollOut = str
    },
    [type.SET_UNREADNUM]( state , str ) {
        state.unreadNum = str
    },
    [type.SET_SHARE]( state , boolean ) {
        state.share.show = boolean
    },
    [type.SET_BIZROLE]( state , str ) {
        state.bizRole = str
    },
    [type.SET_LENDPAGEINFO]( state , object ) {
        state.lendPageInfo = object
    },
    [type.SET_BORROWPAGEINFO]( state , object ) {
        state.borrowPageInfo = object
    },
    [type.SET_LENDLIST]( state , arr ) {
        state.lendList = arr
    },
    [type.SET_BORROWLIST]( state , arr ) {
        state.borrowList = arr
    },
    [type.SET_LENDFILTERSTR]( state , str ) {
        state.lendFilterStr = str
    },
    [type.SET_BORROWFILTERSTR]( state , str ) {
        state.borrowFilterStr = str
    },
    [type.SET_BORROWFILTEROBJ]( state , obj ) {
        state.borrowFilterObj = obj
    },
    [type.SET_ROUTERLIST]( state , router ) {
        if(router.index !== undefined){
            state.routerList.splice(router.index,1)
            return
        }
        state.routerList.push(router.name)
    },
    [type.SET_ROUTERANIMATION]( state , animationName ) {
        state.routerAnimation = animationName
    },
    [type.SET_REPORTINFO]( state , info ) {
        state.reportInfo = info
    },
    [type.SET_SHOWS]( state , info ) {
        state.shows = info
        console.log(state.shows)
    },
    [type.SET_GOHOME]( state , boolean ) {
        state.goHome = boolean
    },
    [type.SET_REPORTID]( state , id ) {
        state.reportId = id
    },
    [type.SET_USERINFO]( state , info ) {
        state.userInfo = info
        Storage.set('51sjd_userInfo',info)
    },
    [type.SET_DOCUMENTCLICK]( state , boolean ) {
        state.documentClick = boolean
    },
    [type.SET_SELECTZINDEX]( state , num ) {
        state.selectZIndex = num
    },
    [type.SET_LOANINDEXREFRESH]( state , boolean ) {
        state.loanIndexRefresh = boolean
    },
    [type.SET_HASTRADEPASSWORD]( state , boolean ) {
        state.hasTradePassword = boolean
    },
    [type.SET_LOGINPASSWORD]( state , password ) {
        state.loginPassword = password
    },
    [type.SET_TRANSACTIONPASSWORD]( state , password ) {
        state.transactionPassword = password
    },
    [type.SET_NEEDLOGIN]( state , boolean ) {
        state.needLogin = boolean
    },
    [type.SET_FUNCIDS]( state , funcIds ) {
        state.funcIds = funcIds
    },
    [type.SET_CITY]( state , cityInfo ) {
        state.cityInfo = cityInfo
    },
    [type.SET_CARINFO]( state , info ) {
        state.carInfo = info
    },
    [type.SET_CARCURRENT]( state , info ) {
        state.carCurrent = info
    },
    [type.SET_COMPANYLIST]( state , list ) {
        state.companyList = list
    },
    [type.SET_SEARCHHISTORY]( state , list ) {
        state.searchHistory = list
    },
    [type.SET_SEARCHHISTORYFORM]( state , form ) {
        state.searchHistoryForm = form
    },
    [type.SET_SEARCHHISTORYCURRENTPAGE]( state , num ) {
        state.searchHistoryCurrentPage = num
    },
    [type.SET_POLICYHISTORY]( state , list ) {
        state.policyHistory = list
    },
    [type.SET_INVOICERESULT]( state , result ) {
        state.invoiceResult = result
    },
    [type.SET_INVOICESUPPORT]( state , list ) {
        state.invoiceSupport = list
    },
    [type.SET_PROVIDENTFUNDCITY]( state , city ) {
        state.providentFundCity = city
    },
    [type.SET_PROVIDENTFUNDRESULT]( state , result ) {
        state.providentFundResult = result
    },
    [type.SET_BLACKLISTRESULT]( state , result ) {
        state.blackListResult = result
    },
    [type.SET_OPERATORSRESULT]( state , result ) {
        state.operatorsResult = result
    },
    [type.SET_CREDITCARDBILLSRESULT]( state , result ) {
        state.creditCardBillResult = result
    },
    [type.SET_STUDENTSTATUSRESULT]( state , result ) {
        state.studentStatusResult = result
    },
    [type.SET_BAODANRESULT]( state , result ) {
        let isEdit = false

        _.each(state.baodanResult,(value,key) => {
            if(value.baodan == result.baodan){
                state.baodanResult.$set(key, result)
                isEdit = true
                return false
            }
        })
        if(!isEdit) state.baodanResult.unshift(result)
    },
    [type.REMOVE_BAODANRESULT]( state , result ) {
        state.baodanResult.$remove(result)
        console.log(state.baodanResult)
    },
    [type.SET_INDEXVIEWFORM]( state , form ) {
        state.indexViewForm = form
    },
    [type.SET_UPDATEDASHBOARD]( state , boolean ) {
        state.updateDashboard = boolean
    },
    [type.SET_DASHBOARD]( state , dashboard ) {
        state.dashboard = dashboard
    },
    [type.SET_REQUESTPARAMS]( state , requestParams ) {
        console.log(requestParams)
        state.requestParams = requestParams
    },
    [type.SET_CHANNEL]( state , channel ) {
        state.channel = channel
    },
    [type.SET_ADMIN]( state , admin ) {
        state.admin = admin
    },
    [type.SET_USERID]( state , userId ) {
        state.userId = userId
    },
    [type.SET_SESSIONID]( state , sessionId ) {
        state.sessionId = sessionId
    },
    [type.SET_AUTHTYPE]( state , type ) {
        state.authType = type
    }

}

export default{ state, mutations }